package com.jcl.recruit.api.corp.controller;

import com.jcl.core.resp.ApiResponse;
import com.jcl.recruit.core.constants.Constants;
import com.jcl.recruit.core.constants.UserExternalLoginConstant;
import com.jcl.recruit.corp.model.Subcompany;
import com.jcl.recruit.corp.service.SubcompanyService;
import com.jcl.recruit.corp.vo.CorpVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 刘明新
 * @date 2018/8/2 下午1:39
 */
@RestController
@RequestMapping("/api/subcompany")
public class SubcompanyController {

    @Autowired
    private SubcompanyService subcompanyService;

    @RequestMapping("/user/corplist")
    public ApiResponse getCorpList() {
        List<Map<String, Object>> list = subcompanyService.userLoginCorpList(
                UserExternalLoginConstant.USER_ACCESS_CATEGORY_WECHAT);
        return ApiResponse.success(list);
    }

    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    public ApiResponse update(@RequestBody CorpVo entity) {

        return ApiResponse.success(Constants.ReturnInfo.SUCCESS_MSG);
    }

    /**
     * 公司信息
     * @return
     */
    @RequestMapping("/detail")
    public ApiResponse findOneDetail(){
        CorpVo corpVo = subcompanyService.getCorpDetail();
        return ApiResponse.success(corpVo);
    }

    /**
     * 公司信息
     * @param superId
     * @return
     */
    @RequestMapping("/getall")
    public Map<String,Object> geTail(Integer superId){
        Map<String,Object> map = new LinkedHashMap<>();
        List<Subcompany> subcompanies = subcompanyService.selectAllComanyInfosBySuperId(superId);
        map.put("type","success");
        map.put("message","执行成功");
        map.put("subcompanys",subcompanies);
        return map;
    }

}
